<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>异步请求</h1>
<div>
    <input type="button" value="异步请求get" @click="f1()">
    <input type="button" value="异步请求post" @click="f2()">
    <h2>{{info}}</h2>
    <a href="/bmi.html">bmi测试</a>
    <hr>
    <a href="/reg.html">注册</a>
    <a href="/login.html">登录</a>
</div>
<!--引入Vue框架-->
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
<!--引入Axios框架-->
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<script>
    let v = new Vue({
        el:"body>div",
        data:{
            info:"vue正常工作"
        },
        methods:{
            f1(){
                //发出异步请求
                axios.get("/helloAxios?info=abc").then(function (response) {
                    //服务器成功响应后的回调方法
                    //response代表响应对象   response.data表示服务器响应的数据
                    alert(response.data);
                })
            },
            f2(){
                let user = {username:"tom",password:"123456",nick:"汤姆"}
                //发出异步的post请求把自定义的对象传递过去
                axios.post("/postAxios",user).then(function (response) {
                    // alert(response.data);
                    v.info=response.data;
                })
            }
        }
    })
</script>

</body>
</html>